﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using com.dz.dataaccess;
using com.dz.common;
using com.dz.entity;
namespace com.dz.components.background
{
    public class DataManager
    {
        BookDao m_book_dao = new BookDao();

        /// <summary>
        /// 章节数据访问对象
        /// </summary>
        BookChapterDao m_book_chapter_dao = new BookChapterDao();

        /// <summary>
        /// 获取各个站点需要抓取的书籍列表
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataSet GetSiteCatchBookList(int i_site_id)
        {
            try
            {
                return m_book_dao.GetSiteCatchBookList(i_site_id, AppConfig.CatchBookChapterMode);
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取各个站点需要抓取的书籍列表失败" + ex.ToString());
                return null;
            }
        }

            /// <summary>
        /// 添加章节信息
        /// </summary>
        /// <param name="i_volume_name"></param>
        /// <param name="i_chapter_name"></param>
        /// <param name="i_update_time"></param>
        /// <param name="i_is_vip"></param>
        /// <param name="i_words_count"></param>
        /// <param name="i_book_id"></param>
        /// <param name="i_site_id"></param>
        /// <returns></returns>
        public long InsertBranckBookChapter(string i_volume_name, string i_chapter_name, DateTime i_update_time, bool i_is_vip, int i_words_count, long i_book_id, int i_site_id, long i_site_book_id,string i_comfrom,int i_order_type)
        {
            try
            {
                return m_book_chapter_dao.InsertBranckBookChapter(i_volume_name, i_chapter_name, i_update_time, i_is_vip, i_words_count, i_book_id, i_site_id, i_site_book_id,i_comfrom,i_order_type);
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加章节信息失败" + ex.ToString());
                return Consts.Failed;
            }
        }

           /// <summary>
        /// 获取存在封面的书籍列表
        /// </summary>
        /// <param name="i_site_id"></param>
        /// <returns></returns>
        public DataSet GetExistsImageBookList(int i_site_id)
        {
            try
            {
                return m_book_dao.GetExistsImageBookList(i_site_id);
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取存在封面的书籍列表失败" + ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// 添加书的信息
        /// </summary>
        public long AddBookInfo(BookInfo model)
        {
            try
            {
                return m_book_dao.AddBookInfo(model);
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加书信息失败" + ex.ToString());
                return Consts.Failed;
            }
        }

        /// <summary>
        /// 获取各个站点需要抓取的书籍列表
       /// </summary>
       /// <param name="i_catch_type">-1 全部重新抓取 0 继续上次记录抓取</param>
       /// <param name="i_site_id">站点编号</param>
       /// <param name="i_order_type">1升序 0 降序</param>
       /// <param name="i_page_index"></param>
       /// <param name="i_page_size"></param>
       /// <param name="i_return_total_count">1需要返回记录总数0不需要</param>
       /// <param name="o_total_count">记录总数</param>
       /// <returns></returns>
        public DataSet GetSiteCatchBookList(int i_catch_type, int i_site_id, int i_order_type, int i_page_index, int i_page_size, int i_return_total_count, out int o_total_count)
        {
            o_total_count = 0;
            try
            {
                return m_book_dao.GetSiteCatchBookList(i_catch_type, i_site_id, i_order_type, i_page_index, i_page_size, i_return_total_count, out o_total_count);
            }
            catch (Exception ex)
            {
                LogHelper.Error("获取站点需要抓取书籍列表失败" + ex.ToString());
                return null;
            }
        }

             /// <summary>
       /// 更新小说封面状态
       /// </summary>
       /// <param name="i_book_id"></param>
       /// <param name="i_exist_image"></param>
       /// <returns></returns>
        public int UpdateBookExistImage(long i_book_id, int i_exist_image)
        {
            try
            {
                return m_book_dao.UpdateBookExistImage(i_book_id, i_exist_image);
            }
            catch (Exception ex)
            {
                LogHelper.Error("更新小说封面状态失败" + ex.ToString());
                return Consts.Failed;
            }
        }
              /// <summary>
        /// 添加书的信息
        /// </summary>
        public long AddCatchBookInterface(BookInfo model)
        {
            try
            {
                return m_book_dao.AddCatchBookInterface(model);
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加书籍信息失败" + ex.ToString());
                return Consts.Failed;
            }
        }
    }
}
